package com.shigu.component.shiro.filter;

import com.shigu.admin.common.service.OemSystemService;
import com.shigu.component.shiro.AuthorityUser;
import com.shigu.mo.enums.SessionEnum;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.*;
import java.io.IOException;

/**
 * 假登陆
 */
@Service("moni_login_filter")
public class MoniLoginFilter implements Filter {
    @Autowired
    OemSystemService oemSystemService;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        Session session = SecurityUtils.getSubject().getSession();
        if (session.getAttribute(SessionEnum.LOGIN_USER.toString())==null){//没登陆
            AuthorityUser user=new AuthorityUser();
//            user.setUserId(5L);
//            user.setNick("18888971971");
//            user.setUserName("18888971971");
            user.setUserId(1L);
            user.setNick("开发维护");
            user.setUserName("kfwh");
            user.setOemVO(oemSystemService.selDefaultOem());
            session.setAttribute(SessionEnum.LOGIN_USER.toString(),user);
        }
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
